package com.taotao.module.bigdata.consumer;


import com.taotao.module.bigdata.consumer.initbean.InitConsumerListen;
import com.taotao.module.bigdata.consumer.service.SocketIoService;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/***
 * @author liutao
 * @desc netty websocket 实现推送消息
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ComponentScan(basePackages = "com.taotao.module")
public class ConsumerApplication {

    public static void main(String[] args) {
        SpringApplication application = new SpringApplication(ConsumerApplication.class);
        application.setBannerMode(Banner.Mode.OFF);
        application.run(args);
        InitConsumerListen initConsumerListen = new InitConsumerListen();
        initConsumerListen.putKafka();
        ExecutorService executorService = Executors.newFixedThreadPool(1);

        executorService.submit(() -> {
            SocketIoService ioService = new SocketIoService();
            try {
                ioService.startServer();
                while (true) {
                    ioService.sendMessageToAllClient("push_qa", "实时推送数据");
                    Thread.sleep(2);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });


    }


}
